import playerHandle from "core/handle/playerHandle"
import eventEmitter from "./eventEmitter"
import Random from "./random"

import { gameConfigHandle } from 'core/config/gameConfig'
import { PlayerModel } from "core/model/playerModel"
import utils from "./utils"
import { rMapData } from "./rMapData"


export let routeApiConfig = {
	isClient: false,
	isLocal: true,
	version: "1.1",
	serverApi: null,
	clientRouteApi: null,
	requestIndex: 0,
	localApiSendMessage: null,
	rMapData: JSON.parse(JSON.stringify(rMapData)),
}

export interface GameTime {
	time: number,
	dayTime: number
}

export interface GameRouteData {
	player: PlayerModel
	time: number,
	dayTime: number
	version: string
	random: Random
	vipLvl: number
	isMonthVip: boolean
	isYearVip: boolean
}


export function localApi(routeName: string, delay: boolean = false) {
	return (target, property, descriptor: PropertyDescriptor) => {
		if (!routeApiConfig.rMapData[routeName + "_" + property]) {
			routeApiConfig.rMapData[routeName + "_" + property] = routeApiConfig.rMapData.rMapIndex++
		}
		let func = descriptor.value
		descriptor.value = (...values) => {
			if (routeApiConfig.isClient) {
				return routeApiConfig.localApiSendMessage(property, func, routeName, delay, ...values)
			} else {
				let res = func(...values)
				return { err: res.err, data: res.data }
			}
		}
	}
}

export let playerUpdateFunc = {
	cb: null,
	headCb: null
}

